package com.hk.Mgr.web.controller.pay;

import com.hk.base.ResponseBase;
import com.hk.commons.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hk.commons.CreateUniqueTokensUtil;

@Controller
public class AppPayGetToken {
	private static Logger logger = LoggerFactory
			.getLogger(AppPayGetToken.class);

	/**
	 * 获取token
	 * */
	@ResponseBody
	@RequestMapping(value = "/pay/getToken", method = RequestMethod.GET)
	public ResponseBase<String> getToken(@RequestParam String userId) {
		ResponseBase<String> result = new ResponseBase();
		try {
			userId = userId.split(",")[0];
			String token = CreateUniqueTokensUtil.getRandomToken(userId);
			logger.info("生成8位UUID,token={},userId={}", token, userId);
			result.setResult(token);
			return result;
		} catch (Exception e) {
			logger.error("获取token失败，userId={}", userId);
			e.printStackTrace();
			result.setResult(null);
			return result;
		}
	}

}
